<?php
/**
 * Created by PhpStorm.
 * User: fengliu
 * Date: 15/8/15
 * Time: 下午2:47
 */

namespace Admin\Controller;


class ConsultationController extends DatabaseController
{
    /**
     * 申请列表
     */
    public function applyList()
    {
        $page = I('get.page', '1', 'intval');
        $model = M('ApplyConsultation');
        $sid=I('get.sid',0,'intval');
        if(!empty($sid))
            $where['doctor_id']=$sid;
        $count = $model->where($where)->count();
        $perPage = C('LIST_ROWS') < 20 ? 20 : C('LIST_ROWS');
        $totalPage = $count / $perPage;
        if ($page != 1 && $page > $totalPage)
            $this->redirect();
        $Page = new \Think\Page($count, $perPage);
        $show = $Page->show();
        $list = $model->where($where)->order('status desc')->page($page, $perPage)->select();
//        var_dump($list,$model->getLastSql());exit;
        $this->assign('page',$show);
        $this->assign('list', $list);
        $this->meta_title = '申请列表';
        $this->display();
    }

    /**
     * 订单列表
     */
    public function orderList(){
        $page = I('get.page', '1', 'intval');
        $model = M('ConsultationOrder');
        $sid=I('get.sid',0,'intval');
        if(!empty($sid))
            $where['doctor_id']=$sid;
        $count = $model->where($where)->count();
        $perPage = C('LIST_ROWS') < 20 ? 20 : C('LIST_ROWS');
        $totalPage = $count / $perPage;
        if ($page != 1 && $page > $totalPage)
            $this->redirect();
        $Page = new \Think\Page($count, $perPage);
        $show = $Page->show();
        $list = $model->where($where)->order('status desc')->page($page, $perPage)->select();
//        var_dump($list,$model->getLastSql());exit;
        $this->assign('page',$show);
        $this->assign('list', $list);
        $this->meta_title = '申请列表';
        $this->display();
    }

    /**
     * 订单明细
     * @param int $id
     * @return void
     */
    public function details($id){
        if(empty($id))
            $id=I('get.id',0,'intval');
        if($id===0){
            $this->error('操作错误,订单id不正确');
        }
        $data=M('ConsultationOrder')->find($id);
        $this->assign('vo',$data);
        $this->meta_title = '订单详情';
        $this->display();
    }
}